package com.jvyou.app.ds.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jvyou.app.common.domain.model.PageResult;
import com.jvyou.app.common.utils.orm.WrapperTool;
import com.jvyou.app.ds.domain.dto.VehicleDto;
import com.jvyou.app.ds.domain.entity.Vehicle;
import com.jvyou.app.ds.mapper.VehicleMapper;
import com.jvyou.app.ds.service.VehicleService;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 教练车基本信息表(Vehicle)表服务实现类
 *
 * @author 橘柚
 * @since 2025-04-16 10:11:39
 */
@Service("vehicleService")
public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> implements VehicleService {

    private QueryWrapper<Vehicle> getWrapper(VehicleDto vehicleDto) {
        QueryWrapper<Vehicle> queryWrapper = new QueryWrapper<>();
        WrapperTool.notEmptyLike(queryWrapper, "plate_number", vehicleDto.getPlateNumber());
        WrapperTool.notEmptyEq(queryWrapper, "vehicle_type", vehicleDto.getVehicleType());
        WrapperTool.notEmptyEq(queryWrapper, "transmission_type", vehicleDto.getTransmissionType());
        WrapperTool.notEmptyEq(queryWrapper, "status", vehicleDto.getStatus());
        return queryWrapper;
    }

    @Override
    public PageResult<Vehicle> pageVehicle(VehicleDto vehicleDto) {
        IPage<Vehicle> page = new Page<>(vehicleDto.getCurrent(), vehicleDto.getPageSize());
        return PageResult.success(page(page, getWrapper(vehicleDto)));
    }

    @Override
    public List<Vehicle> listVehicle(VehicleDto vehicleDto) {
        return list(getWrapper(vehicleDto));
    }
}
